﻿using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TUlingWpf.Heplers;
using TUlingWpf.Messages;
using TUlingWpf.ViewModels;

namespace TUlingWpf.Views
{
    /// <summary>
    /// HomeView.xaml 的交互逻辑
    /// </summary>
    public partial class HomeView : UserControl
    {
        public HomeView()
        {
            InitializeComponent();
            DataContext = App.Current.Service.GetService<HomeViewModel>();
            page.Content = App.Current?.Service?.GetService<IndexView>();
            //处理信使
            WeakReferenceMessenger.Default.Register<IntMessage>(this, (send, arg) =>
            {
                switch (arg.Value)
                {
                    case 1:
                        page.Content = App.Current?.Service?.GetService<IndexView>();
                        break;

                    case 2:
                        page.Content = App.Current?.Service?.GetService<DeviceView>();
                        break;

                    case 3:
                        page.Content = App.Current?.Service?.GetService<UserView>();
                        break;
                }
            });
            //登出消息
            WeakReferenceMessenger.Default.Register<LogOutMessage>(this, (send, arg) =>
            {
                page.Content = App.Current?.Service?.GetService<LoginView>();
                //Width=1200;
                //Height=800;
                Debug.WriteLine("homeeview被打印");
            });
        }
    }
}